package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.dto.MaterialStatisticsDto;
import com.cleaningcloud.cld.domain.excelExport.ProjectRepositoryExprot;
import com.cleaningcloud.cld.domain.excelExport.StockStatisticsExport;
import com.cleaningcloud.cld.service.IMaterialStatisticsService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/materialStatistics")
public class MaterialStatisticsController extends BaseController {

    @Autowired
    private IMaterialStatisticsService materialStatisticsService;

    /**
     * 物资头部统计
     *
     * @return
     */
    @GetMapping("/materialHeadStatistics")
    public AjaxResult materialHeadStatistics() {
        return success(materialStatisticsService.materialHeadStatistics());
    }

    /**
     * 项目统计
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/projectStatistics")
    public TableDataInfo projectStatistics(MaterialStatisticsDto materialStatisticsDto) {
        startPage();
        List<Map<String, Object>> list = materialStatisticsService.projectStatistics(materialStatisticsDto);
        return getDataTable(list);
    }

    /**
     * 项目统计 - 明细
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/projectDetailsList")
    public AjaxResult projectDetailsList(MaterialStatisticsDto materialStatisticsDto) {
        return success(materialStatisticsService.projectDetailsList(materialStatisticsDto));
    }

    /**
     * 类别统计
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/commodityTypeStatistics")
    public TableDataInfo commodityTypeStatistics(MaterialStatisticsDto materialStatisticsDto) {
        List<Map<String, Object>> list = materialStatisticsService.commodityTypeStatistics(materialStatisticsDto);
        return getDataTable(list);
    }

    /**
     * 类别统计 - 明细
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/commodityTypeDetailsList")
    public AjaxResult commodityTypeDetailsList(MaterialStatisticsDto materialStatisticsDto) {
        return success(materialStatisticsService.commodityTypeDetailsList(materialStatisticsDto));
    }


    /**
     * 商品统计
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/commodityStatistics")
    public TableDataInfo commodityStatistics(MaterialStatisticsDto materialStatisticsDto) {
        startPage();
        List<Map<String, Object>> list = materialStatisticsService.commodityStatistics(materialStatisticsDto);
        return getDataTable(list);
    }


    /**
     * 调入明细
     *
     * @param materialStatisticsDto
     * @return
     */
    @GetMapping("/transferDetails")
    public TableDataInfo transferDetails(MaterialStatisticsDto materialStatisticsDto) {
        startPage();
        List<Map<String, Object>> list = materialStatisticsService.transferDetails(materialStatisticsDto);
        return getDataTable(list);
    }

    /**
     * @Author Shaw
     * @Description 备货统计
     * @date: 2025-03-19 15:53
     * @param: //TODO
     */
    @GetMapping("/stockAppDetails")
    public TableDataInfo stockAppDetails(MaterialStatisticsDto materialStatisticsDto) {
        startPage();
        List<Map<String, Object>> list = materialStatisticsService.stockAppDetails(materialStatisticsDto);
        return getDataTable(list);
    }

    /**
     * @Author Shaw
     * @Description 备货统计导出
     * @date: 2025-03-18 9:15
     * @param: //TODO
     */
    @Log(title = "备货统计导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportStockAppDetails")
    public void exportStockAppDetails(HttpServletResponse response, StockStatisticsExport stockStatisticsExport){
        List<StockStatisticsExport> list = materialStatisticsService.exportStockAppDetails(stockStatisticsExport);
        ExcelUtil<StockStatisticsExport> util = new ExcelUtil<StockStatisticsExport>(StockStatisticsExport.class);
        util.exportExcel(response, list, "备货统计");
    }
}
